<template>
  <div id="clist">
    <ul class="list">
      <li v-for="item in list" :key="item.id">
        <div @click="aa(item)">
          <img :src="item.goods_img" alt="">
        </div>
        <p class="title">{{item.goods_name}}</p>
        <p class="xiao">月销：{{item.sales}}</p>
        <div class="car">
          <span>{{item.price|price2}}</span>
          <van-icon @click="changeId(item)" name="cart-o" size='20px'/>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data () {
    return {
      list: []
    }
  },
  props: ['index'],
  mounted () {
    this.$http.post('https://4de16698-d9f4-443a-b416-ef1037cce952.bspapp.com/http/api/get_car_goods_list',{
      sort_type: this.index
    }).then(res => {
      if (res.code !== 1) {
        console.log('出问题');
      } else {
        this.list = res.data
      }
    })
  },
  methods: {
    changeId(item) {
      console.log(item.id);
    },
    aa (item) {
      this.$router.push({path: `goods${item.id}`})
    }
  },
  filters: {
    price2 (val) {
      let val2 = val.toFixed(2)
      return '￥' + val2 
    }
  }
}
</script>

<style lang='scss'>
#clist{
  background-color: #f5f5f7;
}
.list {
  display: flex;
  justify-content:space-between;
  align-content: center;
  flex-wrap: wrap;
  li{
    margin-top: 10px;
    width: 49%;
    background-color: #fff;
    img{
      width: 100%;
      height: 100%;
    }
    p{
      line-height: 0px;
      padding-left: 10px;
    }
    .title{
      padding: 5px 0;
      padding-left: 10px;
      font-size: 14px;
    }
    .xiao{
      font-size: 10px;
      color: grey;
    }
    .car{
      display: flex;
      justify-content: space-between;
      padding: 5px 10px 10px;
      color: #325fb5;
      .van-icon{
        border-radius: 50%;
        width: 20px;
        height: 20px;
        background-color:#ecf3fe;
      }
    }
  }
}
</style>
